package oa.struts.action;

import java.util.Collection;

import javax.annotation.Resource;

import oa.domain.forum.Forum;
import oa.domain.page.PageBean;

import oa.service.ForumManageService;
import oa.struts.action.base.BaseAction;
import oa.util.HQLHelper;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;

@Controller("forumManageAction")
public class ForumManageAction extends BaseAction<Forum> {

	@Resource(name="forumManageService")
	private ForumManageService forumManageService;
	
	public String showAllForum()
	{
		/*Collection<Forum> forumList = this.forumManageService.getAllForum();
		ActionContext.getContext().put("forumList", forumList);*/
		HQLHelper hh = new HQLHelper(Forum.class);
		hh.addOrderBy("o.position", true);
		
		PageBean pageBean = this.forumManageService.getPageBean(hh,currentPage);
		
		ActionContext.getContext().getValueStack().push(pageBean);
		return listAction;
	}
	
	public String addUI()
	{
		return addUI;
	}
	
	public String add()
	{
		Forum forum = new Forum();
		BeanUtils.copyProperties(this.getModel(), forum);
		this.forumManageService.saveForum(forum);
		return action2action;
	}
	
	public String updateUI()
	{
		Forum forum = this.forumManageService.getForumById(this.getModel().getId());
	    ActionContext.getContext().getValueStack().push(forum);
		return updateUI;
	}
	
	public String update()
	{
		Forum forum = this.forumManageService.getForumById(this.getModel().getId());
		BeanUtils.copyProperties(this.getModel(), forum);
		this.forumManageService.upateForum(forum);
		return action2action;
	}
	
	public String delete()
	{
		this.forumManageService.deleteForum(this.getModel().getId());
		return action2action;
	}

	
	public String moveUp()
	{
		this.forumManageService.moveUp(this.getModel().getId());
		return action2action;
	}
	
	public String moveDown()
	{
		this.forumManageService.moveDown(this.getModel().getId());
		return action2action;
	}
}
